package com.vhly.aapt;

import com.vhly.aapt.io.OrderInputStream;

import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 2010-4-26
 * Time: 16:03:53
 */
public class ResValue extends ResXMLTree_node {
    public short size;
    public byte always0;
    public ValueType valutType;
    public byte type;
    public int data;
    private static final int TYPE_REFERENCE = 0x1;
    private static final int TYPE_ATTRIBUTE = 0x02;
    private static final int TYPE_STRING = 0x03;
    private static final int TYPE_FLOAT = 0x04;
    private static final int TYPE_DIMENSION = 0x05;
    private static final int TYPE_FRACTION = 0x06;
    private static final int TYPE_FIRST_INT = 0x10;
    private static final int TYPE_INT_DEC = 0x10;
    private static final int TYPE_INT_HEX = 0x11;
    private static final int TYPE_INT_BOOLEAN = 0x12;
    private static final int TYPE_FIRST_COLOR_INT = 0x1c;
    private static final int TYPE_INT_COLOR_ARGB8 = 0x1c;
    private static final int TYPE_INT_COLOR_RGB8 = 0x1d;
    private static final int TYPE_INT_COLOR_ARGB4 = 0x1e;
    private static final int TYPE_INT_COLOR_RGB4 = 0x1f;
    private static final int TYPE_LAST_COLOR_INT = 0x1f;
    private static final int TYPE_LAST_INT = 0x1;

    @Override
    public String toXML() {
        String ret = "";
        switch (type) {
            case TYPE_REFERENCE:
                ret = "@+/" + data;
                break;
            case TYPE_ATTRIBUTE:
                break;
            case TYPE_STRING:
                break;
            case TYPE_FLOAT:
                ret = "" + Float.intBitsToFloat(data);
                break;
            case TYPE_DIMENSION:
                ret = ""+data;
                break;
            case TYPE_FRACTION:
                break;
            case TYPE_FIRST_INT:
                ret = "" + data;
                break;
//            case TYPE_INT_DEC:
//                break;
            case TYPE_INT_HEX:
                ret = "0x" + Integer.toHexString(data);
                break;
            case TYPE_INT_BOOLEAN:
                ret = data == 1 ? "true" : "false";
                break;
            case TYPE_FIRST_COLOR_INT:
                ret = "#" + Integer.toHexString(data);
                break;
            case TYPE_INT_COLOR_RGB8:
                ret = "#" + Integer.toHexString(data);
                break;
            case TYPE_INT_COLOR_ARGB4:
                ret = "#" + Integer.toHexString(data);
                break;
            case TYPE_INT_COLOR_RGB4:
                ret = "#" + Integer.toHexString(data);
                break;

        }
        return ret;
    }

    @Override
    public void read(OrderInputStream din) throws IOException {
        size = din.readShort();
        always0 = din.readByte();
        type = din.readByte();
        data = din.readInt();
    }
}